//
//  ViewController.m
//  YaoHeAPP
//
//  Created by mac on 15/11/20.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "ViewController.h"
#import "LoginVC.h"
#import "Controller.h"
#import "HearderVC.h"
#import "ShopingCar.h"
#import "IssueVC.h"
#import "OrderVC.h"
#import "MySelfVC.h"
#import "Tool.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"ViewController"];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"ViewController"];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    width=self.view.frame.size.width;
    height=self.view.frame.size.height;
    [self getOnePath];
}

-(void)getOnePath
{
    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSString *filePath = [docPath stringByAppendingPathComponent:@"one"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath])
    {
        //创建滚动视图放置导航图片
        UIScrollView*scrollView=[[UIScrollView alloc]init];
        scrollView.frame=CGRectMake(0, 0, width, height);
        scrollView.contentSize=CGSizeMake(5*width, 0);
        scrollView.pagingEnabled=YES;
        scrollView.showsHorizontalScrollIndicator=NO;
        scrollView.bounces=NO;
        [self.view addSubview:scrollView];
        for (NSInteger i=0; i<5; i++)
        {
            UIImageView*oneImg=[[UIImageView alloc]init];
            oneImg.frame=CGRectMake(i*width,0, scrollView.frame.size.width, scrollView.frame.size.height);
//            oneImg.image=[UIImage imageNamed:[NSString stringWithFormat:@"guide%ld",i+1]];
            oneImg.image=[UIImage imageNamed:[NSString stringWithFormat:@"Newguide%ld",i+1]];
//            if (i==0) {
//                oneImg.backgroundColor=[UIColor whiteColor];
//            }
//            if (i==1) {
//                oneImg.backgroundColor=[UIColor colorWithRed:222.f/255.f green:246.f/255.f blue:255.f/255.f alpha:1];
//            }
//            if (i==2) {
//                oneImg.backgroundColor=[UIColor colorWithRed:244.f/255.f green:244.f/255.f blue:244.f/255.f alpha:244.f/255.f];
//            }
            oneImg.contentMode=UIViewContentModeScaleAspectFill;
            oneImg.clipsToBounds=YES;
            [scrollView addSubview:oneImg];
            
            UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
            button.frame=CGRectMake(4*width+100,height/2+100, width-200, height/2-100);
            button.tag=10;
            [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
            [scrollView addSubview:button];
        }
        //创建一个路径
        [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
   
    else
    {
        NSString*successStr=[[NSUserDefaults standardUserDefaults]objectForKey:@"状态"];
        if ([successStr isEqualToString:@"成功"]) {
            RootTabBarViewController *rootTabBarViewController = [RootTabBarViewController rootViewController];
            [rootTabBarViewController changeRootViewControllerTo:0];
        } else {
            LoginVC*loginVC=[[LoginVC alloc]init];
            UINavigationController*naVC=[[UINavigationController alloc]initWithRootViewController:loginVC];
            naVC.navigationBarHidden=YES;
            UIWindow*window=[UIApplication sharedApplication].delegate.window;
            window.rootViewController=naVC;
        }
    }
    
}

//进入登录页面
//-(void)enterNext
//{
//    NSString*successStr=[[NSUserDefaults standardUserDefaults]objectForKey:@"状态"];
//    if ([successStr isEqualToString:@"成功"])
//    {
//        [Tool gotoMain:width nameindex:0];
//    }
//    else{
//        LoginVC*loginVC=[[LoginVC alloc]init];
//        UINavigationController*naVC=[[UINavigationController alloc]initWithRootViewController:loginVC];
//        naVC.navigationBarHidden=YES;
//        UIWindow*window=[UIApplication sharedApplication].delegate.window;
//        window.rootViewController=naVC;
//    }
//}

//第一次进入应用程序
- (void)click {
    //进入登录界面
    LoginVC *loginVC = [[LoginVC alloc] init];
    UINavigationController*naVC=[[UINavigationController alloc]initWithRootViewController:loginVC];
    naVC.navigationBarHidden=YES;
    UIWindow*window=[UIApplication sharedApplication].delegate.window;
    window.rootViewController=naVC;

}

@end
